package com.dst.controller;

import com.dst.eneity.Brand;
import com.dst.eneity.Phone;
import com.dst.service.BrandService;
import com.dst.service.PhoneService;
import com.dst.service.impl.BrandServiceImpl;
import com.dst.service.impl.PhoneServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;

@WebServlet(urlPatterns = "/phone/addPhoneController")
public class AddPhoneController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        int state =Integer.parseInt(req.getParameter("state"));
        BigDecimal price = new BigDecimal(req.getParameter("price"));
        int pinpai = Integer.parseInt(req.getParameter("pinpai"));
        PhoneService phoneService = new PhoneServiceImpl();
        phoneService.addPhoneService(new Phone(null,name,price,state,pinpai));
        resp.sendRedirect(req.getContextPath()+"/phone/selectAllController");
    }
}
